package leetcode_1601_1700;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class LeeCode_1630 {
    public static void main(String[] args) {
        System.out.println(checkArithmeticSubarrays(new int[]{4, 6, 5, 9, 3, 7}, new int[]{0, 0, 2}, new int[]{2, 3, 5}));
    }
    private static List<Boolean> checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {
        int n = l.length;
        List<Boolean> ans = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            int[] arr = Arrays.copyOfRange(nums, l[i], r[i] + 1);
            Arrays.sort(arr);
            for (int j = 1; j < arr.length; j++) {
                if (arr[j] - arr[j - 1] != arr[1] - arr[0]){
                    ans.add(false);
                    break;
                }
                if (j == arr.length - 1){
                    ans.add(true);
                }
            }
        }
        return ans;
    }
}
